package com.cszjzx.member.action;

import java.util.ArrayList;
import java.util.List;

import com.cszjzx.member.po.Member;
import com.cszjzx.member.service.MemberService;
import com.cszjzx.member.service.MemberServiceImpl;
import com.cszjzx.member.util.ExcelUtilsDao;
import com.cszjzx.member.util.ExcelUtilsDaoImpl;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ExcuteExportExcelAction extends ActionSupport{
	private String searchName;	//导出的查询条件
	private String searchValue1,searchValue2;	//导出的查询值
	private String fileName;	//导出的文件名
	private List<String> stage1;		//第一阶段需要导出的字段
	private List<String> stage2;		//第二阶段需要导出的字段
	private List<String> stage3;		//第三阶段需要导出的字段
	private List<String> stage4;		//第四阶段需要导出的字段
	private MemberService memberService;
	private ExcelUtilsDao excelUtilsDao;
	private String message;
	
	public String getSearchValue1() {
		return searchValue1;
	}

	public void setSearchValue1(String searchValue1) {
		this.searchValue1 = searchValue1;
	}

	public String getSearchValue2() {
		return searchValue2;
	}

	public void setSearchValue2(String searchValue2) {
		this.searchValue2 = searchValue2;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<String> getStage1() {
		return stage1;
	}

	public void setStage1(List<String> stage1) {
		this.stage1 = stage1;
	}

	public List<String> getStage2() {
		return stage2;
	}

	public void setStage2(List<String> stage2) {
		this.stage2 = stage2;
	}

	public List<String> getStage3() {
		return stage3;
	}

	public void setStage3(List<String> stage3) {
		this.stage3 = stage3;
	}

	public List<String> getStage4() {
		return stage4;
	}

	public void setStage4(List<String> stage4) {
		this.stage4 = stage4;
	}

	public String getSearchName() {
		return searchName;
	}

	public void setSearchName(String searchName) {
		this.searchName = searchName;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	
	/**
	 * 里面path是干什么用的
	 * 
	 */
	@SuppressWarnings("unused")
	public String execute(){
		List<String> stage = new ArrayList<String>();
		System.out.println(stage1);
		for(int i=0;stage1!=null && i<stage1.size();i++){
			stage.add(stage1.get(i));
		}
		for(int i=0;stage2!=null && i<stage2.size();i++){
			stage.add(stage2.get(i));
		}
		for(int i=0;stage3!=null && i<stage3.size();i++){
			stage.add(stage3.get(i));
		}
		for(int i=0;stage4!=null && i<stage4.size();i++){
			stage.add(stage4.get(i));
		}
		System.out.println("size:"+stage.size());
		if(stage.size() == 0){
			message = "请选择导出字段";
			return "error";
		}
		if(stage1 == null){
			stage.add("idcard");
			stage.add("name");
			stage.add("department");
			stage.add("major");
		}
		memberService = new MemberServiceImpl();
		List<Member> members=null;
		if(searchName.equals("") || searchName == null || searchName.equals("请选择")){
			message = "请选择导出条件";
			return "error";
		}
		else if (searchName.equals("全校")) {
			members = memberService.findAll();
		}
		else if (searchName.equals("department") || searchName.equals("process")) {
			members = memberService.getMembersByNameAndValue(searchName, searchValue1);
		}
		else if (searchName.equals("major")) {
			members = memberService.getMembersByNameAndValue(searchName, searchValue2);
		}
		excelUtilsDao = new ExcelUtilsDaoImpl();
		String path=excelUtilsDao.expMembersByFieldsToExcel(members, stage, fileName+".xls");
		return SUCCESS;
	}
}
